﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Rbac.Services.Roles;
using Rbac.Services.Roles.Dto;
using System;

namespace RbacSystem.Controllers
{
    [Route("/[controller]/[action]")]
    [ApiController]
    public class RoleController : ControllerBase
    {
        private readonly IRoleMenuService service;

        public RoleController(IRoleMenuService service)
        {
            this.service = service;
        }

        [HttpGet]
        public IActionResult Query()
        {
            return new JsonResult(service.Query());
        }

        [HttpGet]
        public IActionResult QueryByRole(int RoleId)
        {
            return new JsonResult(service.QueryByRole(RoleId));
        }

        [HttpPost]
        public IActionResult AssignPermission(PermissionDto permission)
        {
            return Ok(service.AssignPermission(permission));
        }

        /// <summary>
        /// 数据协商
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult QueryPermission()
        {
            return new JsonResult(service.QueryPermission());
        }
    }
}
